/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGE_KNIFE_C_IJOB_QUEUE_H
#define IMAGE_KNIFE_C_IJOB_QUEUE_H
#include <cstddef>
#include "request/imageknife_request_internal.h"

namespace ImageKnifePro {
class IJobQueue {
public:
    enum class EndPhase {
        LOADING,
        DECODING,
    };

    struct Job {
    public:
        Job() = default;
        Job(std::shared_ptr<ImageKnifeRequestInternal> request, ImageRequestType type);
        Job(std::shared_ptr<ImageKnifeRequestInternal> request, ImageRequestType type,
            std::string memoryKey, int traceId);

        std::shared_ptr<ImageKnifeRequestInternal> request = nullptr;
        ImageSource* imageSrc = nullptr;
        ImageRequestType type;
        std::string memoryKey;
        std::string fileKey;

        int jobId;
        EndPhase phase = EndPhase::DECODING;
        std::string loadingKey;
        bool writeFileCache = true;
        bool writeMemoryCache = true;
    };

    /**
     * 在主线程调用，获取唯一job id,可以作为traceId
     * @return 返回job id
     */
    static int GetUniqueJobId();
    
    IJobQueue() = default;
    virtual ~IJobQueue() = default;

    // 获取队列长度
    virtual size_t GetQueueLength() = 0;

    // 添加队列元素
    virtual void Add(Job queueElement) = 0;

    // 移除并返回队列头部元素
    virtual Job Pop() = 0;
};
} // namespace ImageKnightC
#endif // IMAGE_KNIFE_C_IJOB_QUEUE_H
